$(function(){
	$("#loading-first").fadeOut(500);
	var page=1;
	var tddata=[
		{
			key:'oil_station_name',
			type:1,
			url:''
		},{
			key:'scale2',
			type:1,
			url:'{:url("detail")}',
			id:137
		},{
			key:'charge_person',
			type:1,
			url:''
		},{
			key:'contact_number',
			type:1,
			url:''
		},{
			key:'address',
			type:1,
			url:''
		}];
	var addoperation=`<td>
						<div class="tpl-table-black-operation operate">
							<a class='exit' >
								<i class="am-icon-pencil"></i> 编辑
							</a>
							<a href="javascript:;" class='detail'>
								<i class="am-icon-pencil"></i> 详情
							</a>
							<a href="javascript:;" class="tpl-table-black-operation-del delete" >
								<i class="am-icon-pencil"></i> 删除
							</a>
						</div>
					</td>`
	var data={};
	data.page=page;
	data.pagenum=10;
	var where_json={};
	where_json.company_id=['in',$('.company_all_id').val()]
	console.log($('.company_all_id').val())
	{if $Think.get.scale}
		where_json.scale=['in',"{$Think.get.scale}"]
	{/if}
	{if $Think.get.oil_station_name}
		where_json.oil_station_name=['like',"%{$Think.get.oil_station_name}%"]
	{/if}
	{if $Think.get.oil_station_name|| $Think.get.scale}
	
	{/if}
	data.where_json=JSON.stringify(where_json)
	ajaxpetrol(data)
	function ajaxpetrol(data){
		Load()
		$.ajax({
			type:'post',
			data:data,
			url:"{:url('adminapi/Oilstation/oilStationList')}",
			success:function(res){
				Load(1)
				console.log(res)
				if(res.code==1){
					var petrollist=res.list
					for(var i=0;i<res.list.length;i++){
						if(res.list[i].scale==3){
							res.list[i].scale2='大型'
						}else if(res.list[i].scale==2){
							res.list[i].scale2='中型'
						}else if(res.list[i].scale==1){
							res.list[i].scale2='小型'
						}
					}
					$('tbody').html(tbodymainf2(petrollist, 1, tddata, addoperation, 'oil_station_id'))
					$('.pagination').html(pagechang1(res.count, 10, page))
					$('.exit').on('click',function(){
						window.location.href='{:url("petroladd")}?oil_station_id='+$(this).closest('tr').data('id')
					})
					$('.detail').on('click',function(){
						var that=this
						layer.open({
						  type: 2,
						  title:false,
						  shadeClose: true,
						  shade: 0.8,
						  area: ['500px', '70%'],
						  content: "{:url('petroldetail')}?op=search&oil_station_id="+$(that).closest('tr').data('id'),
						  
						}); 
					})
					//删除
					$('.delete').on('click',function(){
						var deletedata={
							oil_station_ids:$(this).closest('tr').data('id')
						}
						deleteindex=layer.open({
							type: 1,
							title: false,
							id: "delete" ,
							content: "<div class='am-vertical-align-middle' style='width:100%;text-align:center'>是否删除</div>",
							btn: ['确定', '取消'],
							btnAlign: 'c' //按钮居中
								,
							shade: 0 //不显示遮罩
								,
							yes: function() {
								var deleteload = layer.load(1, {
									shade: [0.1, '#fff'] //0.1透明度的白色背景
								});
								$.ajax({
									method: "POST",
									url: '{:url("adminapi/Oilstation/delete")}',
									data: deletedata,
									success: function(res) {
										if(res.code == 1) {
											console.log(data)
											Msg('删除成功')
											ajaxpetrol(data)
											
											
										} else if(res.code == 0) {
											
											Err(res.msg ? res.msg : '操作失败，稍候再试');
										}
										layer.close(deleteload);
										layer.close(deleteindex);
			
									},
									error:function(){
										layer.close(deleteload);
											layer.close(deleteindex);
										Err('请求失败')
									}
								});
			
							},
							btn2: function() {
								layer.closeAll();
							}
						});
					})
					
					$('.laquo').on('click',function(){
						console.log(data)
						page-=1;
						data.page=page
						ajaxpetrol(data)
					})
					$('.pageli').on('click',function(){
						console.log(data)
						page=$(this).html()
						data.page=page
						ajaxpetrol(data)
					})
					//下一页
					$('.raquo').on('click',function(){
						page+=1;
						data.page=page
						ajaxpetrol(data)
					});
				}
			},
			error:function(){
				Load(1)
				Err('请求失败')
			}
		})
	}

})
